package com.yfp.machine.service.impl;

import com.yfp.machine.domain.MachineError;
import com.yfp.machine.mapper.MachineErrorMapper;
import com.yfp.machine.service.MachineErrorService;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * (MachineError)表服务实现类
 *
 * 
 * @since 2023-12-14 13:53:34
 */
@Service("machineErrorService")
public class MachineErrorServiceImpl implements MachineErrorService {
    @Resource
    private MachineErrorMapper machineErrorMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param machineId 主键
     * @return 实例对象
     */
    @Override
    public MachineError queryById(String machineId) {
        return this.machineErrorMapper.queryById(machineId);
    }

    /**
     * 分页查询
     *
     * @param machineError 筛选条件
     * @param pageRequest  分页对象
     * @return 查询结果
     */
    @Override
    public Page<MachineError> queryByPage(MachineError machineError, PageRequest pageRequest) {
        long total = this.machineErrorMapper.count(machineError);
        return new PageImpl<>(this.machineErrorMapper.queryAllByLimit(machineError, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param machineError 实例对象
     * @return 实例对象
     */
    @Override
    public MachineError insert(MachineError machineError) {
        this.machineErrorMapper.insert(machineError);
        return machineError;
    }

    /**
     * 修改数据
     *
     * @param machineError 实例对象
     * @return 实例对象
     */
    @Override
    public MachineError update(MachineError machineError) {
        this.machineErrorMapper.update(machineError);
        return this.queryById(machineError.getMachineId());
    }

    /**
     * 通过主键删除数据
     *
     * @param machineId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String machineId) {
        return this.machineErrorMapper.deleteById(machineId) > 0;
    }

    @Override
    public List<MachineError> queryMachineErrorByMachineId(String machineId) {
        return this.machineErrorMapper.queryMachineErrorByMachineId(machineId);
    }
}
